package com.example.romancalc;

import com.vaadin.data.Item;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextField;

/**
 * @author Luis Oscar Trigueiros
 *
 */
public class ParamsFieldFactory extends DefaultFieldFactory {

	private static final String COMMON_FIELD_WIDTH = "12em";

	/**
	 * 
	 */
	private static final long serialVersionUID = 9113807345979560740L;

	@Override
	public Field createField(Item item, Object propertyId, Component uiContext) {
		if ("op1".equals(propertyId)) {
			TextField tf = (TextField) super.createField(item, propertyId, uiContext);
			tf.setCaption("");
			tf.setRequired(true);
			tf.addStyleName("calcInput");
			tf.setRequiredError("Please enter op1");
			//tf.setDescription("Please enter Roman number");
			tf.setWidth(COMMON_FIELD_WIDTH);
			tf.addValidator(new RomanNumberValidator("Invalid number for op1"));
			return tf;
		}
		if ("op2".equals(propertyId)) {
			TextField tf = (TextField) super.createField(item, propertyId, uiContext);
			tf.setCaption("+");
			tf.setRequired(true);
			tf.setRequiredError("Please enter op2");
			//tf.setDescription("Please enter Roman number");
			tf.setWidth(COMMON_FIELD_WIDTH);
			tf.addValidator(new RomanNumberValidator("Invalid number for op2"));
			tf.addStyleName("calcInput");
			return tf;
		} 
		return super.createField(item, propertyId, uiContext);
	}

}
